from exercise import Database
from flask import Flask,request,jsonify



app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False

cache = dict()


@app.route('/addition',methods=['GET','POST'])
def exercise_addition():
    print("缓存值为:",cache)
    database = Database(db = "exercise",table = "static_motion")
    database.connection()
    value = int(request.values.get("value"))
    key  = int(request.values.get("key"))
    cache[key]=int(cache[key])+value
    val =[cache[key],key]
    database.update_data(val)
    database.guan()
    return "操作成功!"

@app.route('/view',methods=['GET','POST'])
def exercise_view():
    database = Database(db = "exercise",table = "static_motion")
    database.connection()
    result,info = database.view_table()
    cache.update(info)
    database.guan()
    return jsonify(result)
    
if __name__=="__main__":
    app.run(host = "0.0.0.0",port=80)
